package cn;

/**
 Dates类
 @author SSYING

 */
public class Dates {
    /**
     * @param date 前一天日期
     * @return 后一天日期
     */
    public String getDate(String date) {
        int[] monArray = new int[] {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        date = date.replace('年', ',');
        date = date.replace('月', ',');
        date = date.replace('日', ',');

        String[] string = date.split(",");

        Integer year = Integer.valueOf(string[0]);
        Integer month = Integer.valueOf(string[1]);
        Integer day = Integer.valueOf(string[2]);



        if (Boolean.TRUE.equals(judgeYear(year)) || Boolean.TRUE.equals(judgeMonth(month)) || Boolean.TRUE.equals(judgeDay(day)) || Boolean.TRUE.equals(judgeMonthYearDay(month, year, day))) {
            return "该输入日期格式有误";
        }
        if (Boolean.TRUE.equals(judgeLeapYear(year))) {
            monArray[2]++;
        }

        if (day == monArray[month]) {
            if (Boolean.TRUE.equals(judgeMonth2(month))) {
                month = 1;
                day = 1;
                year++;
            } else {
                day = 1;
                month++;
            }
        }
        if (day < monArray[month]) {
            day++;
        }
        if (day > monArray[month]) {
            return "该输入日期格式有误";
        }

        return year + "年" + month + "月" + day + "日";
    }
    /**
     * 判断年份是否规范
     * @param a 年份
     * @return boolean

     */

    Boolean judgeYear(int a) {
        Boolean flag = false;
        if (a < 1964 || a > 2050) {
            flag = true;
        }
        return flag;

    }
    /**
     * 判断月份是否规范
     * @param b 月份
     * @return boolean

     */
    Boolean judgeMonth(int b) {
        Boolean flag = false;
        if (b < 1 || b > 12) {
            flag = true;
        }
        return flag;
    }
    /**
     * 判断天数是否规范
     * @param c 天
     * @return boolean

     */
    Boolean judgeDay(int c) {
        Boolean flag = false;
        if (c < 1 || c > 31) {
            flag = true;
        }
        return flag;
    }
    /**
     * 判断是否为闰年
     * @param d 年份
     * @return boolean

     */
    Boolean judgeLeapYear(int d) {
        Boolean flag = false;
        if (d % 4 == 0 && d % 100 != 0 || d % 400 == 0) {
            flag = true;
        }
        return flag;
    }
    /**
     * 判断前一天是否为范围内最后一天
     * @param a 月份
     * @param b 年份
     * @param c 天
     * @return boolean

     */
    Boolean judgeMonthYearDay(int a, int b, int c) {
        Boolean flag = false;
        if (a == 12 && b == 2050 && c == 31) {
            flag = true;
        }
        return flag;
    }
    /**
     * 判断是否为12月
     * @param a 月份
     * @return boolean

     */
    Boolean judgeMonth2(int a) {
        Boolean flag = false;
        if (a == 12) {
            flag = true;
        }
        return flag;
    }


}